<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: nz::nodes::calc::ScalarDivNode Class Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>nz</b></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes.html">nodes</a></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes_1_1calc.html">calc</a></li><li class="navelem"><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html">ScalarDivNode</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">nz::nodes::calc::ScalarDivNode Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Represents a scalar division operation node in a computational graph.  
 <a href="#details">More...</a></p>
<div class="dynheader">
Inheritance diagram for nz::nodes::calc::ScalarDivNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_scalar_div_node__inherit__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_scalar_div_node_inherit__map" alt="Inheritance graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_scalar_div_node_inherit__map" id="anz_1_1nodes_1_1calc_1_1_scalar_div_node_inherit__map">
<area shape="rect" title="Represents a scalar division operation node in a computational graph." alt="" coords="5,80,212,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="50,5,167,32"/>
<area shape="poly" title=" " alt="" coords="111,48,111,80,106,80,106,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for nz::nodes::calc::ScalarDivNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_scalar_div_node__coll__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_scalar_div_node_coll__map" alt="Collaboration graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_scalar_div_node_coll__map" id="anz_1_1nodes_1_1calc_1_1_scalar_div_node_coll__map">
<area shape="rect" title="Represents a scalar division operation node in a computational graph." alt="" coords="5,80,212,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="50,5,167,32"/>
<area shape="poly" title=" " alt="" coords="111,48,111,80,106,80,106,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:ac04d8d6de4becf4e1c7911e99c131b7d" id="r_ac04d8d6de4becf4e1c7911e99c131b7d"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ac04d8d6de4becf4e1c7911e99c131b7d">ScalarDivNode</a> (<a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *input, Tensor::value_type scalar)</td></tr>
<tr class="memdesc:ac04d8d6de4becf4e1c7911e99c131b7d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructor to initialize a <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> for scalar division.  <br /></td></tr>
<tr class="separator:ac04d8d6de4becf4e1c7911e99c131b7d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4728d1f10d35d7e71b11acd32ee1a26d" id="r_a4728d1f10d35d7e71b11acd32ee1a26d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d">forward</a> () override</td></tr>
<tr class="memdesc:a4728d1f10d35d7e71b11acd32ee1a26d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Forward pass for the <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> to perform scalar division.  <br /></td></tr>
<tr class="separator:a4728d1f10d35d7e71b11acd32ee1a26d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9b72dc5618e8e11790756c91116719e4" id="r_a9b72dc5618e8e11790756c91116719e4"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a9b72dc5618e8e11790756c91116719e4">backward</a> () override</td></tr>
<tr class="memdesc:a9b72dc5618e8e11790756c91116719e4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Backward pass for the <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> to propagate gradients.  <br /></td></tr>
<tr class="separator:a9b72dc5618e8e11790756c91116719e4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_classnz_1_1nodes_1_1_node"><td colspan="2" onclick="javascript:dynsection.toggleInherit('pub_methods_classnz_1_1nodes_1_1_node')"><img src="closed.png" alt="-"/>&#160;Public Member Functions inherited from <a class="el" href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></td></tr>
<tr class="memitem:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a687ee9c34eb61f8f28caa201ca42696e"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a687ee9c34eb61f8f28caa201ca42696e">print</a> (std::ostream &amp;os) const</td></tr>
<tr class="memdesc:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Prints the type, data, and gradient of the node.  <br /></td></tr>
<tr class="separator:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a9b85913e12422bb4ac2fff483427bb47"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a9b85913e12422bb4ac2fff483427bb47">dataInject</a> (Tensor::value_type *data, bool grad=false) const</td></tr>
<tr class="memdesc:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data into a relevant tensor object, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a609f1730085dd1d31e0ddcbbae48a065"><td class="memTemplParams" colspan="2">template&lt;typename Iterator &gt; </td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a609f1730085dd1d31e0ddcbbae48a065">dataInject</a> (Iterator begin, Iterator end, const bool grad=false) const</td></tr>
<tr class="memdesc:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_af8b4bab3271df92ca1f0914f7a97b1e8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#af8b4bab3271df92ca1f0914f7a97b1e8">dataInject</a> (const std::initializer_list&lt; Tensor::value_type &gt; &amp;data, bool grad=false) const</td></tr>
<tr class="memdesc:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from a std::initializer_list into the output tensor of the <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a>, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Represents a scalar division operation node in a computational graph. </p>
<p>The <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> class performs element-wise division of a tensor by a scalar value. It is used in computational graphs to implement normalization or scaling operations, which are fundamental in machine learning and numerical computations.</p>
<p>Key features:</p><ul>
<li><b>Forward Pass</b>: Divides each element of the input tensor by a scalar value and stores the result in the <code>output</code> tensor.</li>
<li><b>Backward Pass</b>: Propagates gradients from the <code>output</code> tensor back to the input tensor by scaling the gradients with the reciprocal of the scalar value.</li>
<li><b>Error Handling</b>: Ensures that the scalar value is non-zero during construction to prevent division by zero errors.</li>
<li><b>Shape Preservation</b>: Maintains the shape of the input tensor in the <code>output</code> tensor.</li>
<li><b>Gradient Management</b>: Tracks whether gradients are required for the operation based on the properties of the input tensor.</li>
</ul>
<p>This class is part of the <code><a class="el" href="namespacenz_1_1nodes.html" title="Contains classes and functionality for nodes in a neural network or computational graph.">nz::nodes</a></code> namespace and is optimized for scalar-tensor division operations in computational graphs.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The scalar value must be non-zero. An exception is thrown during construction if this condition is not met.</li>
<li>A warning is issued indicating that scalar operations do not support saving to files, and users are encouraged to use matrix operations for model persistence.</li>
</ul>
</dd></dl>
<h3><a class="anchor" id="autotoc_md92"></a>
Usage Example:</h3>
<div class="fragment"><div class="line"><span class="comment">// Example: Using ScalarDivNode for scalar division</span></div>
<div class="line">InputNode input({3, 3}, <span class="keyword">true</span>);  <span class="comment">// Create an input node with shape {3, 3}</span></div>
<div class="line">input.output-&gt;fill(10.0f);  <span class="comment">// Fill the input tensor with value 10.0</span></div>
<div class="line"> </div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html">ScalarDivNode</a> scalar_div_node(&amp;input, 2.0f);  <span class="comment">// Divide the input tensor by 2.0</span></div>
<div class="line">scalar_div_node.forward();  <span class="comment">// Perform the forward pass</span></div>
<div class="line">scalar_div_node.backward();  <span class="comment">// Propagate gradients in the backward pass</span></div>
<div class="line"> </div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;Output: &quot;</span> &lt;&lt; *scalar_div_node.output &lt;&lt; std::endl;  <span class="comment">// Print the result</span></div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html">nz::nodes::calc::ScalarDivNode</a></div><div class="ttdoc">Represents a scalar division operation node in a computational graph.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l01350">Nodes.cuh:1350</a></div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward()</a> for the <a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward</a> pass implementation. </dd>
<dd>
<a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward()</a> for the gradient propagation in the <a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward</a> pass.</dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::invalid_argument</td><td>If the scalar value is zero, as division by zero is undefined.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section warning"><dt>Warning</dt><dd><ul>
<li>Scalar operations are not yet supported for saving to files. Use matrix operations as an alternative.</li>
</ul>
</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/05 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cuh_source.html#l01350">1350</a> of file <a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="ac04d8d6de4becf4e1c7911e99c131b7d" name="ac04d8d6de4becf4e1c7911e99c131b7d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac04d8d6de4becf4e1c7911e99c131b7d">&#9670;&#160;</a></span>ScalarDivNode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">nz::nodes::calc::ScalarDivNode::ScalarDivNode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *</td>          <td class="paramname"><span class="paramname"><em>input</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::value_type</td>          <td class="paramname"><span class="paramname"><em>scalar</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Constructor to initialize a <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> for scalar division. </p>
<p>The constructor initializes a <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code>, which performs element-wise division of the output tensor of the input node by a scalar value. It validates the scalar value, sets up the node's input connections, determines the gradient tracking requirement, and prepares the output tensor with the appropriate shape and properties.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">input</td><td>A pointer to the input node. Its <code>output</code> tensor will be divided by the scalar value. </td></tr>
    <tr><td class="paramname">scalar</td><td>The scalar value to divide the input tensor by.</td></tr>
  </table>
  </dd>
</dl>
<ul>
<li>The constructor verifies that the scalar value is non-zero. If the scalar is zero, an exception is thrown to prevent division by zero errors.</li>
<li>The input node is added to the <code>inputs</code> vector to establish the connection in the computational graph.</li>
<li>It initializes the <code>output</code> tensor with the same shape as the input tensor and determines whether the output tensor should track gradients based on the input tensor's gradient requirement.</li>
<li>A warning is issued to inform the user that scalar operations currently do not support saving to files, encouraging the use of matrix operations for models requiring persistence.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The scalar value must be non-zero to ensure valid division. An exception will be thrown if this condition is not met.</li>
<li>The scalar value is stored internally in the <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> instance and used during the forward and backward passes.</li>
</ul>
</dd></dl>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::invalid_argument</td><td>If the scalar value is zero, as division by zero is undefined.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section warning"><dt>Warning</dt><dd><ul>
<li>Scalar operations are not yet supported for saving to files. Use matrix operations as an alternative.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward()</a> for the <a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward</a> pass implementation. </dd>
<dd>
<a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward()</a> for the gradient propagation in the <a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward</a> pass.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/05 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00208">208</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a9b72dc5618e8e11790756c91116719e4" name="a9b72dc5618e8e11790756c91116719e4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9b72dc5618e8e11790756c91116719e4">&#9670;&#160;</a></span>backward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::ScalarDivNode::backward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Backward pass for the <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> to propagate gradients. </p>
<p>The <code><a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward()</a></code> method computes the gradient of the loss with respect to the input tensor by scaling the gradient of the output tensor using the reciprocal of the scalar value. This ensures the gradients are correctly propagated back through the computational graph.</p>
<ul>
<li>The method first checks if the input tensor requires gradients. If true, a CUDA kernel (<code>ScalarDiv</code>) is launched to compute the scaled gradients.</li>
<li>The gradient computation is performed as <code>grad_input[i] = grad_output[i] / scalar</code> for each element, where <code>grad_output</code> is the gradient of the <code>output</code> tensor.</li>
<li>The resulting gradients are stored in the gradient tensor of the input node.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The backward pass uses the same scalar value as in the forward pass, ensuring consistency in gradient computation.</li>
<li>The scalar value must be non-zero to avoid undefined behavior.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward()</a> for the scalar division computation in the <a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward</a> pass.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/05 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a0a9ecbaa3d790ba38e8218aca7837fd0">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00227">227</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_scalar_div_node_a9b72dc5618e8e11790756c91116719e4_cgraph.png" border="0" usemap="#aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_a9b72dc5618e8e11790756c91116719e4_cgraph" alt=""/></div>
<map name="aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_a9b72dc5618e8e11790756c91116719e4_cgraph" id="aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_a9b72dc5618e8e11790756c91116719e4_cgraph">
<area shape="rect" title="Backward pass for the ScalarDivNode to propagate gradients." alt="" coords="5,39,181,81"/>
<area shape="rect" href="namespacenz_1_1krnl.html#a27bc4025be4253d5fffae2bf1b43b3af" title="Kernel function to perform scalar division on the GPU." alt="" coords="229,47,358,73"/>
<area shape="poly" title=" " alt="" coords="181,57,213,57,213,63,181,63"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#ab4b2eb422e0e1ee44bdfdc0eb94457ce" title="Returns a reference to the singleton instance of the StreamManager." alt="" coords="406,5,591,48"/>
<area shape="poly" title=" " alt="" coords="358,47,390,42,391,47,359,52"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#a46ce59b45de432842454aadf00b93791" title="Asynchronously submits a CUDA kernel with stream&#45;ordered dependency management." alt="" coords="406,72,591,115"/>
<area shape="poly" title=" " alt="" coords="359,68,391,73,390,78,358,73"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#a1de1cf3aadea137faf90a2f9b4b7abe2" title="Acquires CUDA stream from pool using round&#45;robin scheduling." alt="" coords="639,39,825,81"/>
<area shape="poly" title=" " alt="" coords="591,77,623,73,624,78,592,83"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#adb1078a67c6e38932d7d58c2adb05ec0" title="Synchronizes CUDA stream execution until data writes complete." alt="" coords="639,105,825,148"/>
<area shape="poly" title=" " alt="" coords="592,104,624,109,623,114,591,109"/>
</map>
</div>

</div>
</div>
<a id="a4728d1f10d35d7e71b11acd32ee1a26d" name="a4728d1f10d35d7e71b11acd32ee1a26d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4728d1f10d35d7e71b11acd32ee1a26d">&#9670;&#160;</a></span>forward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::ScalarDivNode::forward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Forward pass for the <code><a class="el" href="classnz_1_1nodes_1_1calc_1_1_scalar_div_node.html" title="Represents a scalar division operation node in a computational graph.">ScalarDivNode</a></code> to perform scalar division. </p>
<p>The <code><a class="el" href="#a4728d1f10d35d7e71b11acd32ee1a26d" title="Forward pass for the ScalarDivNode to perform scalar division.">forward()</a></code> method computes the element-wise division of the input tensor by the scalar value. It uses CUDA kernels to execute the operation efficiently on the GPU.</p>
<ul>
<li>A CUDA kernel (<code>ScalarDiv</code>) is launched to compute the division for each element in the input tensor.</li>
<li>The grid and block dimensions are calculated dynamically based on the size of the output tensor to optimize parallel computation on the GPU.</li>
<li>The result of the division is stored in the <code>output</code> tensor.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The division operation is performed as <code>output[i] = input[i] / scalar</code> for each element of the tensor.</li>
<li>Ensure the scalar value is non-zero, as division by zero will result in undefined behavior.</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward()</a> for gradient propagation in the <a class="el" href="#a9b72dc5618e8e11790756c91116719e4" title="Backward pass for the ScalarDivNode to propagate gradients.">backward</a> pass.</dd></dl>
<dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/12/05 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a8a828c2e91a4aa2a9ab7b94554e4685b">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00221">221</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>
<div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_scalar_div_node_a4728d1f10d35d7e71b11acd32ee1a26d_cgraph.png" border="0" usemap="#aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_a4728d1f10d35d7e71b11acd32ee1a26d_cgraph" alt=""/></div>
<map name="aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_a4728d1f10d35d7e71b11acd32ee1a26d_cgraph" id="aclassnz_1_1nodes_1_1calc_1_1_scalar_div_node_a4728d1f10d35d7e71b11acd32ee1a26d_cgraph">
<area shape="rect" title="Forward pass for the ScalarDivNode to perform scalar division." alt="" coords="5,39,181,81"/>
<area shape="rect" href="namespacenz_1_1krnl.html#a27bc4025be4253d5fffae2bf1b43b3af" title="Kernel function to perform scalar division on the GPU." alt="" coords="229,47,358,73"/>
<area shape="poly" title=" " alt="" coords="181,57,213,57,213,63,181,63"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#ab4b2eb422e0e1ee44bdfdc0eb94457ce" title="Returns a reference to the singleton instance of the StreamManager." alt="" coords="406,5,591,48"/>
<area shape="poly" title=" " alt="" coords="358,47,390,42,391,47,359,52"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#a46ce59b45de432842454aadf00b93791" title="Asynchronously submits a CUDA kernel with stream&#45;ordered dependency management." alt="" coords="406,72,591,115"/>
<area shape="poly" title=" " alt="" coords="359,68,391,73,390,78,358,73"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#a1de1cf3aadea137faf90a2f9b4b7abe2" title="Acquires CUDA stream from pool using round&#45;robin scheduling." alt="" coords="639,39,825,81"/>
<area shape="poly" title=" " alt="" coords="591,77,623,73,624,78,592,83"/>
<area shape="rect" href="classnz_1_1cu_strm_1_1_stream_manager.html#adb1078a67c6e38932d7d58c2adb05ec0" title="Synchronizes CUDA stream execution until data writes complete." alt="" coords="639,105,825,148"/>
<area shape="poly" title=" " alt="" coords="592,104,624,109,623,114,591,109"/>
</map>
</div>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/include/NeuZephyr/<a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a></li>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/src/<a class="el" href="_nodes_8cu_source.html">Nodes.cu</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
